package com.bj58.mis.apm.server.kylin.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * json文件解析成对象
 */
public class ModelParseUtil {

    public static <T> List<T> readMetaData(String projectFold, Class<T> clazz){
        List<T> list = new ArrayList<>();

        File dir = new File(projectFold);
        if(dir.exists()){
            File[] ps = dir.listFiles();
            if(ps.length > 0){
                for(File pf : ps){
                    String json = FileUtil.readFile(pf);
                    if(FileUtil.isSuccess(json)){
                        list.add(JsonUtil.fromJson(json, clazz));
                    }
                }
            }
        }
        return list;
    }

    public static <T> T createMode(File file, Class<T> clazz){
        String json = FileUtil.readFile(file);
        if(FileUtil.isSuccess(json)){
            return JsonUtil.fromJson(json, clazz);
        }
        return null;
    }

}
